package com.dferreira.languagesteach.utils;

import android.content.Context;

import com.dferreira.repository.data_models.PackageMetadata;
import com.dferreira.repository.data_models.PackageMetadataState;
import com.dferreira.repository.data_models.Repository;

public class DefaultLanguagesData {
    private final Repository defaultRepository;
    private final PackageMetadata[] defaultPackagesMetadata;
    private final DataPaths dataPaths;

    /*Constant values from the package*/
    private static final int default_pkg_id = 1;
    private static final String default_pkg_name = "languages";
    private static final String default_pkg_description = "dummyDescription";
    private static final int default_pkg_version = 1;
    private static final String default_pkg_author = "danielFerreira";
    private static final long default_pkg_compressed_size = 37146;
    private static final long default_pkg_uncompressed_size = 49828;
    private static final String default_pkg_url = "localhost";


    /**
     * Constructor
     *
     * @param context global information about an application environment.
     */
    public DefaultLanguagesData(Context context) {
        final String pkgName;
        final String pkgDescription;
        final Integer pkgVersion;
        final String pkgAuthor;
        final Long pkgCompressedSize;
        final Long pkgUncompressedSize;
        final String url;

        dataPaths = new DataPaths(context);

        // Initializes constants
        pkgName = default_pkg_name;
        pkgDescription = default_pkg_description;
        pkgVersion = default_pkg_version;
        pkgAuthor = default_pkg_author;
        pkgCompressedSize = default_pkg_compressed_size;
        pkgUncompressedSize = default_pkg_uncompressed_size;
        url = default_pkg_url;

        //

        defaultRepository = new Repository() {
            {
                setVersion(0);
                setUrl(url);
            }
        };

        defaultPackagesMetadata = new PackageMetadata[]{new PackageMetadata() {
            {
                setId(default_pkg_id);
                setName(pkgName);
                setDescription(pkgDescription);
                setVersion(pkgVersion);
                setAuthor(pkgAuthor);
                setCompressedSize(pkgCompressedSize);
                setUncompressedSize(pkgUncompressedSize);
                setUrl(url);
                setPath(dataPaths.getPackagesPath());
                setDependencies(null);
                setState(PackageMetadataState.Installed);
            }
        }};
    }

    /**
     * @return Array from the packages that require to be present to the app start
     */
    public PackageMetadata[] getDefaultPackagesMetadata() {
        return defaultPackagesMetadata;
    }

    /**
     * @return default existent repository
     */
    public Repository getDefaultRepository() {
        return defaultRepository;
    }
}
